package com.geek.controller;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.geek.domain.Order;
import com.geek.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * ShardingSphere-Proxy : 配置代理
 * 使用代理作为数据源
 *
 */
@RequestMapping("/order")
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    Snowflake snowflake = IdUtil.createSnowflake(1, 1);

    @PostMapping("/add")
    public void add() {
        List list = new ArrayList();
        for (int i = 0; i < 1; i++) {
            for (int j = 0; j < 15; j++) {
                Order order = new Order();
                order.setOrderId(snowflake.nextId());
                order.setUserId(Long.valueOf(j));
                order.setUsername("张三");
                list.add(order);
            }
        }
        orderService.add(list);
    }


    @PutMapping("/edit")
    public void edit(@RequestBody Order order) {
        orderService.edit(order);
    }

    @GetMapping("/get")
    public List<Order> get() {
        return orderService.get();
    }

    @DeleteMapping("/del/{orderId}")
    public void delete(@PathVariable Long orderId) {
        orderService.delete(orderId);
    }

}
